package com.jibei.mendo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jibei.mendo.R;
import com.jibei.mendo.utils.MyFunc;

import java.util.List;

/**
 * Created by lhl on 2019/8/24.
 */
public class ExigenceStopAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<String> strings;
    private ExigenceStopListener mExigenceStopListener;

    public ExigenceStopAdapter(Context context, List<String> strings, ExigenceStopListener mExigenceStopListener) {
        this.mContext = context;
        this.strings = strings;
        this.mExigenceStopListener = mExigenceStopListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_exigence_stop, viewGroup, false);
        return new ExigenceStopViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        // string = strings.get(position);
        String string = Integer.valueOf(strings.get(position), 16).toString();
        ((ExigenceStopViewHolder) viewHolder).mText.setText(string);
        Log.d("lhl", "idx:" + string);
        ((ExigenceStopViewHolder) viewHolder).mText.setBackgroundColor(mContext.getResources().getColor(R.color.blue));
        ((ExigenceStopViewHolder) viewHolder).mText.setOnClickListener(v -> {

            mExigenceStopListener.onExigenceStopListener(v, position);
        });
//        ((ExigenceStopViewHolder) viewHolder).mText.setVisibility(View.INVISIBLE);
    }

    @Override
    public int getItemCount() {
        //Log.e("lhl", "某个矩阵下的急停从机个数>>>" + strings.size());
        return strings.size();
    }

    private class ExigenceStopViewHolder extends RecyclerView.ViewHolder {

        private TextView mText;

        public ExigenceStopViewHolder(View itemView) {
            super(itemView);
            mText = itemView.findViewById(R.id.tv_id);
        }
    }

    public interface ExigenceStopListener {
        void onExigenceStopListener(View mView, int position);
    }
}
